// http://api.douban.com/v2/user/1000001?apikey=XXX
// http://api.douban.com/v2/movie/subject/1764796
const rp = require('request-promise-native');
const childProcess = require('child_process');

async function fetchMovie(params) {
    const url = `http://api.douban.com/v2/movie/subject/${params.doubanId}`;
    const res = await rp(url);
    return res;
}

(async ()=>{
    let movies = [
        { doubanId: '26897450',
          poster: 'https://img3.doubanio.com/view/photo/l_ratio_poster/public/p2510316112.jpg',
          title: '困兽之斗',
          rate: 4 },
        { doubanId: '27053244',
          poster: 'https://img3.doubanio.com/view/photo/l_ratio_poster/public/p2503174325.jpg',
          title: '台湾往事',
          rate: 7.4 }];

    // childProcess.on('message', data=>{
    //     movies = data.result || [];
    // })

    movies.map(async movie=>{
        let movieData = await fetchMovie(movie);
        try {
            movieData = JSON.parse(movieData);
            console.log(movieData.tags);
            console.log(movieData.summary);
        } catch (error) {
            console.log(error);
        }
        // console.log(movieData);
    })

})()